<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left aui-btn" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">债权转让</div>
    </header>
    <div class="aui-bar-nav-d"></div>


    <style>
        body {
            background: #fff;
        }
    </style>
    <div class="user-claims-t">
        <ul>
            <li class="active list_type" tapmode onclick="zhaiquan_list(1);" id="list_type1">可转让债权</li>
            <li class="list_type" tapmode onclick="zhaiquan_list(2);" id="list_type2">购买记录</li>
        </ul>
    </div>

    <div id="list">
        <!-- <div class="user-claims">
            <div class="claims-item">
                <div class="claims-item-icon">推荐</div>
                <div class="claims-item-t">
                    <p>

                        <img src="image/licai-znlc.png" alt="">
                    </p>
                    <span>折让1000元</span>
                </div>
                <ul class="claims-item-d">
                    <li>
                        <span></span> 待收本金（元）
                    </li>
                    <li>
                        <span></span> 待收收益(元)
                    </li>
                    <li>
                        <button>立即转让</button> 剩余期限天
                    </li>
                </ul>
            </div>

        </div> -->
    </div>

    <script type="text/template" id="template">
        {{~it:value:index}}
        <div class="user-claims type1">
            <div class="claims-item">
                <!-- <div class="claims-item-icon">推荐</div> -->
                <div class="claims-item-t">
                    <p>
                        {{=value.productName}}
                        <!-- <img src="image/licai-znlc.png" alt=""> -->
                    </p>
                    {{? value.transferStatus==1}}
                    <span class="diy">正在转让</span> {{??}}{{?}}
                </div>
                <ul class="claims-item-d">
                    <li>
                        <span>{{=value.principalTransferDS}}</span> 待收本金（元）
                    </li>
                    <li>
                        <span>{{=value.interestTransferDS}}</span> 待收收益(元)
                    </li>
                    <li>{{? value.transferStatus==null}}
                        <button tapmode onclick="details('{{=value.dealSN}}');">立即转让</button> 剩余期限{{=value.howMuchDay}}天 {{?? value.transferStatus==0}}
                        <button tapmode onclick="details('{{=value.dealSN}}');">立即转让</button> 剩余期限{{=value.howMuchDay}}天 {{?? value.transferStatus==1}}
                        <button tapmode onclick="chexiao('{{=value.deal_id}}');" style="background: #c0c0c0">撤销</button> {{?? value.transferStatus==2}}
                        <button style="background: #c0c0c0">回收中</button> {{?? value.transferStatus==3}}
                        <button style="background: #c0c0c0">回收完成</button> {{??}}{{?}}
                    </li>
                    <input type="hidden" id="name{{=value.dealSN}}" value="{{=value.productName}}">
                    <input type="hidden" id="mount{{=value.dealSN}}" value="{{=value.principalTransferDS}}">
                    <input type="hidden" id="deal_id{{=value.dealSN}}" value="{{=value.deal_id}}">
                </ul>
            </div>
        </div>
        {{~}}
    </script>

    <script type="text/template" id="template2">
        {{~it:value:index}}
        <div class="user-claims type2">
            <div class="claims-item">
                <!-- <div class="claims-item-icon">推荐</div> -->
                <div class="claims-item-t">
                    <p>
                        {{=value.productName}}
                        <!-- <img src="image/licai-znlc.png" alt=""> -->
                    </p>
                    <!-- <span>折让1000元</span> -->
                </div>
                <ul class="claims-item-d">
                    <li>
                        <span>{{=value.principalTransferDS}}</span> 待收本金（元）
                    </li>
                    <li>
                        <span>{{=value.interestTransferDS}}</span> 待收收益(元)
                    </li>
                    <li>
                        <button style="background:#c0c0c0">已购买</button> 剩余期限{{=value.endDate}}天
                    </li>
                </ul>
            </div>
        </div>
        {{~}}
    </script>

</body>
<script type="text/javascript">
    var n = '';
    var type = 1;
    apiready = function() {

        load_list();
        // addObserver();
        down_refresh();
        // alert(userid);
    }

    function down_refresh() {

        api.setRefreshHeaderInfo({
            visible: true,
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...',
            showTime: true
        }, function(ret, err) {
            page = 1;

            if (type == 1) {
                load_list();
            }
            if (type == 2) {
                load_list2();
            }
        });
    }

    function addObserver() {
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err) {
            if (type == 1) {
                load_list(true);
            }
            if (type == 2) {
                load_list2(true);
            }
        });
    }

    function zhaiquan_list(num) {
        if (num == type) {
            return;
        }

        if (num == 1) {
            type = 1;
            $(".list_type").removeClass("active");
            $("#list_type1").addClass('active');
            $("#type2").remove();
            load_list();
        }

        if (num == 2) {
            type = 2;
            $(".list_type").removeClass("active");
            $("#list_type2").addClass('active');
            $("#type1").remove();
            load_list2();
        }
    }

    // function load_list(n) {
    function load_list() {

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        userid = $api.getStorage('userid');
        // if (n) {
        //     page += 1;
        // } else {
        //     page = 1;
        // }
        api.ajax({
            url: webAddress + '/index.php?ctl=deal&act=my_transfer_list&doSign=1',
            method: 'post',
            data: {
                values: {
                    user_id: userid
                },
            }
        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                updateList(ret);
                api.refreshHeaderLoadDone();
                api.hideProgress();
            }
        });

    }

    function updateList(data) {
        if (data == '') {
            // alert('没有记录！');
            api.toast({
                msg: '没有记录!',
                duration: 2000,
                location: 'bottom'
            });
        }
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html);

        // if (page == 1) {
        //     $api.html(list, html);
        // } else {
        //
        //     if (!data) {
        //         api.toast({
        //             msg: '没有更多了',
        //             duration: 2000,
        //             location: 'bottom'
        //         });
        //         return;
        //     }
        //     $api.append(list, html);
        // }
    }

    // function load_list2(n) {
    function load_list2() {
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        userid = $api.getStorage('userid');
        // if (n) {
        //     page += 1;
        // } else {
        //     page = 1;
        // }
        api.ajax({
            url: webAddress + '/index.php?ctl=deal&act=my_transfer_list_buys&doSign=1',
            method: 'post',
            data: {
                values: {
                    user_id: userid
                },
            }
        }, function(ret, err) {
            if (ret) {
                // alert(JSON.stringify(ret));
                updateList2(ret);
                api.refreshHeaderLoadDone();
                api.hideProgress();
            } else {
                // alert( JSON.stringify( err ) );
                alert(err.msg);
                api.hideProgress();
                // api.closeWin({});
            }
        });
    }

    function updateList2(data) {
        if (data == '') {
            // alert('没有记录！');
            api.toast({
                msg: '没有记录!',
                duration: 2000,
                location: 'bottom'
            });
        }
        var template = $api.byId('template2');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');
        $api.html(list, html);
    }

    function details(id) {
        var name = $("#name" + id).val();
        var mount = $("#mount" + id).val();
        var deal_id = $("#deal_id" + id).val();
        // alert(id);
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'user_claims_details',
            url: './user_claims_details.html',
            pageParam: {
                deal_sn: id,
                name: name,
                mount: mount,
                deal_id: deal_id,
            }
        });
    }

    function chexiao(id) {
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        api.ajax({
            url: 'http://big-wealth.com/index.php?ctl=deal&act=do_reback',
            method: 'post',
            data: {
                values: {
                    deal_id: id
                },
            }
        }, function(ret, err) {
            if (ret) {
                // alert( JSON.stringify( ret ) );
            } else {
                // alert( JSON.stringify( err.body ) );
                if (err.body == '1') {
                    alert('撤销成功！');
                    load_list();
                    api.hideProgress();
                } else {
                    alert("请求错误");
                }
            }
        });

    }

    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
